package net.cyndeline.entitySystem

/**
 * Marks any class that can be sent as an event to an entity.
 */
trait Event {
  private var cancelled = false
  private var canBeCancelled = true
  
  /**
   * Cancels the event and prevents it from being sent to
   * any more systems.
   */
  def cancel() = cancelled = true
  
  /**
   * Call this method once an events effect has been applied to an entity.
   * Makes it impossible to cancel the event.
   */
  def makeNoncancellable() = canBeCancelled = false
  
  /**
   * Once an event has been processed, it should not be possible to consume
   * it, since it's no longer possible to "cancel" it.
   */
  def isCancelled = cancelled && canBeCancelled
  
  /**
   * Creates a deep copy of the event.
   */
  def copy: Event
  
  /**
   * Adds another event to this one, creating a new event with their
   * combined data.
   * 
   * Example: Adding two damage events results in a new event that deals
   * their combined damage amount.
   * 
   * If an event cannot be added this way (either because the underlying event 
   * classes are incompatible or the event is not additive in nature), 
   * it should return a deep copy of itself.
   */
  def +(other: Event): Event = this.copy
}